<template>
  <div class="content">角色管理</div>
  <el-table
    :data="filterTableData"
    height="400px"
    style="width: 100%; height: calc(100% - 36px)"
  >
    <el-table-column type="index" />
    <el-table-column label="角色名" prop="name" align="center" />
    <el-table-column align="right">
      <template #header>
        <el-input v-model="search" placeholder="Type to search" />
      </template>
      <template #default="scope">
        <el-button @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button type="danger" @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    class="page"
    v-model:currentPage="currentPage"
    v-model:page-size="pageSize"
    :page-sizes="[100, 200, 300, 400]"
    :small="small"
    :disabled="disabled"
    :background="background"
    layout="total, sizes, prev, pager, next, jumper"
    :total="400"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  >
  </el-pagination>
</template>

<script lang="ts" setup>
import { ref, computed, reactive } from "vue";

interface User {
  id: number;
  name: string;
}
const currentPage = ref(4);
const pageSize = ref(100);
const small = ref(false);
const background = ref(false);
const disabled = ref(false);
let tableData: User[] = reactive([]);
for (let i = 0; i < 30; i++) {
  tableData.push({
    id: i,
    name: `User ${i}`,
  });
}
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
};
const search = ref("");
const filterTableData = computed(() =>
  tableData.filter(
    (data) =>
      !search.value ||
      data.name.toLowerCase().includes(search.value.toLowerCase())
  )
);
const handleEdit = (index: number, row: User) => {
  console.log(index, row);
};
const handleDelete = (index: number, row: User) => {
  console.log(index, row);
  tableData.splice(index, 1);
};
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  height: 60px;
  line-height: 60px;
  background: #ededed;
}
.page {
  display: flex;
  justify-content: flex-end;
}
</style>
